<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!--edge浏览器H5兼容设置-->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!--360浏览器H5兼容设置-->
		<meta name="renderer" content="webkit" />
		<title>注册</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!--导入核心文件-->
		<script src="../bootstrap3/js/holder.js"></script>
		<link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
		<script src="../bootstrap3/jquery-1.9.1.min.js"></script>
		<script src="../bootstrap3/js/bootstrap.js"></script>
		<!-- 字体图标 -->
		<link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
		<link rel="stylesheet" type="text/css" href="../css/top.css" />
		<link rel="stylesheet" type="text/css" href="../css/index.css" />
		<link rel="stylesheet" type="text/css" href="../css/layout.css" />
		<link rel="stylesheet" type="text/css" href="../css/reg.css" />
		<link rel="stylesheet" type="text/css" href="../css/footer.css" />
		<link rel="shortcut icon" href="../favicon.ico"/>
	</head>
	<body>
		<div class="container mycontent text-left">
			<!--透明层 -->
			<div class="regDiv">
				<p>新用户注册</p>
				<!--表单开始-->
				<form id="form-reg" class="form-horizontal" role="form">
					<!--用户名-->
					<div class="form-group">
						<!--<label class="col-md-3 control-label">用户名：</label>-->
						<div class="col-md-8">
							<input name="username" type="text" class="form-control" placeholder="请输入用户名">
						</div>
					</div>
					<!--密码-->
					<div class="form-group">
						<!--<label class="col-md-3 control-label"> 密码：</label>-->
						<div class="col-md-8">
							<input name="password" type="text" class="form-control" placeholder="请输入密码">
						</div>
					</div>
					<!--确认密码-->
					<div class="form-group">
						<!--<label class="col-md-3 control-label"> 确认密码：</label>-->
						<div class="col-md-8">
							<input name="password2" type="text" class="form-control" placeholder="请再次输入密码">
						</div>
					</div>
					<!--验证码-->
					<div class="form-group">
						<!--<label for="verification" class="col-md-3 control-label"> 验证码：</label>-->
						<div class="col-md-8">
							<input name="verification" type="text" class="form-control-diy" id="verification"  placeholder="请输入验证码">
							<img name="imgCode" id="imgCode" ref="vcImg" src="/users/getImage" alt="验证码">
						</div>
					</div>
					<!--手机号-->
					<div class="form-group">
						<!--<label for="verification" class="col-md-3 control-label"> 手机号：</label>-->
						<div class="col-md-8">
							<input name="verification" type="text" class="form-control-diy" id="iphone"  placeholder="请输入手机号">
							<button id="btn-getCode" class="btn btn-default" type="submit">获取验证码</button>
						</div>
					</div>

					<!--提交按钮-->
					<div class="form-group">
						<label class="col-md-3 control-label"></label>
						<div class="col-md-8">
							<input id="btn-reg" class="btn btn-primary" type="button" value="立即注册" />
							<span class="pull-right"><small>已经有账号？</small><a href="login.html">登录</a></span>
						</div>
					</div>
				</form>
			</div>
		</div>
	</body>

	<script type="text/javascript">

		// 重新获取表单验证码
		$("#imgCode").click(function (){
			$("#imgCode").attr("src","/login/getImage?"+Math.random());
		});

		//获取手机验证码按钮
		$("#btn-getCode").click(function() {
			console.log($("#form-reg").serialize());
			$.ajax({
				url: "/login/sendPhoneCode",
				type: "POST",
				data: $("#form-reg").serialize(),
				dataType: "json",
				success: function(json) {
					if (json.state == 200) {
						alert("发送成功！");
					} else {
						alert("发送失败！" + json.message);
					}
				},
				error: function (xhr) {
					alert("发送验证码服务异常" + xhr.status);
				}
			});
		});

		//监听注册按钮被点击
		$("#btn-reg").click(function() {
			console.log($("#form-reg").serialize());
			$.ajax({
				url: "/login/reg",
				type: "POST",
				data: $("#form-reg").serialize(),
				dataType: "json",
				success: function(json) {
					if (json.state == 200) {
						alert("注册成功！");
						location.href = "login.html";
					} else {
						alert("注册失败！" + json.message);
					}
				},
				error: function (xhr) {
					alert("注册返回异常" + xhr.status);
					//location.href = "login.html";
				}
			});
		});
	</script>
</html>